'''
功能层：封装业务流程；
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import sys
sys.path.append(r'..')

from web_bases.base_page import BasePage
class BaiduPage(BasePage):
    url = r'https://www.baidu.com/'

    kw_loc = (By.ID, 'kw')
    su_loc = (By.ID, 'su')
    #登录定位
    login_btn_loc = (By.XPATH,'//*[@id="s-top-loginbtn"]')
    username_loc = (By.ID,'TANGRAM__PSP_11__userName')
    password_loc = (By.ID,'TANGRAM__PSP_11__password')
    agree_loc = (By.ID,'TANGRAM__PSP_11__isAgree')
    login_submit_loc = (By.ID,'TANGRAM__PSP_11__submit')
    #打开hao123
    hao123_loc = (By.XPATH, '//*[@id="s-top-left"]/a[2]')
    def __init__(self,dr):
        super().__init__(dr)
        self.get_url(self.url)
    def search(self,kw):
        self.element_clear(self.kw_loc)
        self.input_element(self.kw_loc,kw)
        self.element_click(self.su_loc)
        sleep(3)
    def login(self,username,password):
        self.element_click(self.login_btn_loc)
        sleep(3)
        self.element_clear(self.username_loc)
        self.input_element(self.username_loc,username)
        self.element_clear(self.password_loc)
        self.input_element(self.password_loc, password)
        self.element_click(self.agree_loc)
        self.element_click(self.login_submit_loc)
        sleep(3)
    def hao123(self):
        self.element_click(self.hao123_loc)
        sleep(3)

if __name__ == '__main__':
    kw = 'selenium'
    username = '123'
    password = '456'
    chrome_location = r'D:\chrom browser\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location
    dr = webdriver.Chrome(options=options)
    dr.maximize_window()
    baidu_page = BaiduPage(dr)
    #搜索测试
    # baidu_page.search(kw)
    #登录测试
    # baidu_page.assert(username, password)
    #打开hao123
    # baidu_page.hao123()